<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>经济管理学院</title>
<link rel="stylesheet" href='css/style.css' type="text/css">

</head>
<script type='text/javascript' src='js/prototype.js'></script>
<script type='text/javascript' src='js/sha1.js'></script>
<script type='text/javascript' src='js/public.js'></script>
<script type="text/javascript">
var code; 

function login() {
	var userId = document.getElementById("userId").value;
	var userPwd = hex_sha1(document.getElementById("userPwd").value);
	var inputCode = document.getElementById("htmlcode1").value;
	var params = "userId=" + userId + "&userPwd=" + userPwd;
	
	
 if(userId=="")
	 {
	 alert("用户名和密码不能为空！");
	 }
 else if (inputCode=="") {
		alert("请输入验证码！");
		 createCode();
	}
	else if(inputCode != code){
		 alert("验证码输入错误！");
		   createCode();
	}
 else{
	new Ajax.Request("json/login", {
		method : "post",
		parameters : params,
		onComplete : function(request) {
		
			var res = request.responseText.evalJSON();
			
			if (res["result"]["flag"] == "true") {
				
				if(res["result"]["pri"]=="1"){
					window.location.href="TeacherIndex.html";
				}
				else
					window.location.href="StudentIndex.html";
			} else
				alert("用户名或密码错误！");
		},
		asynchronous : true
	});
	}
}
function createCode()   
{    
  code = "";  
  var codeLength = 4;
  var checkCode = document.getElementById("htmlcode2");  
  var selectChar = new Array(0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');//所有候选组成验证码的字符，当然也可以用中文的  
     
  for(var i=0;i<codeLength;i++)  
  {    
     
  var charIndex = Math.floor(Math.random()*36);  
  code +=selectChar[charIndex];          
    
  }  
 
  if(checkCode)  
  {  
   
    checkCode.value = code;
  
  }  
    
} 

	
</script>
<body onload="online()">
	<div id="header">

			<div id="nav">
				<ul style="	float: left;padding: 0 20px;text-align: center;line-height: 50px;">
					<li style="float: left; font-size: 28px">经管院学术讲坛事务系统</li>
				</ul>
                   <ul class="horizon">
			
			<li class="login">
				<ul class="vertical">
			<li class="userInfo"><a>&nbsp;欢迎使用</a></li>
			
		</ul>
	</li>
			
		</ul>
			</div>
		
			
		
	
	</div>
	<div id="main" >
        <div style=" width:21%; height:660px; border-right: 3px #660033 solid;  float:left; background-color:rgb(242, 247, 252);"></div>
		<div style="width:78%;font-size: 20px; float:right">
        <div style="margin-top:150px; margin-left:200px;height:300px; border:2px solid #ccc; width:450px;">
         <div style="margin-top:50px; margin-left:50px;">
			<form method="post">
				学号:<br>
				<input name="userId" size="35" id="userId" style="height: 25px;background:none;width: 250px; border:1px solid #CCC"><br>
				密码:<br>
				<input type="password" id="userPwd" name="userPwd" size="35" style="height: 25px;background:none;width: 250px; border:1px solid #CCC"><br>
				验证码：<br><input onclick="createCode()" id="htmlcode1" style="height: 25px;background:none;width: 250px; border:1px solid #CCC"><input
								id="htmlcode2" style="width: 80px; margin-left:10px;height: 25px; background: gray; border: 0;"
								onClick="createCode()" readonly="readonly" /> <a href="#"
								onClick="createCode()" style="font-size: 12px">看不清?</a><br><br>
				 <input type="button" value="登录" onclick="login()"
					style="border:1px solid; border-color:#999;  height: 28px; width: 250px; font-size: 20px;">&nbsp;&nbsp;<a href="Register.html" style="text-decoration:none; font-size:16px;">注册</a>
			</form>
        </div>
        </div>
                <div style="font-size:14px; margin-left:100px; margin-top:150px;">
           	<span id="online">当前在线人数:</span>
    	    <span style="margin-left:150px">Copyright &copy; 2013  经济管理学院 北京市海淀区清华东路35号 邮编：100083</span>
        </div>
		</div>

	</div>

</body>
</html>